import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../common/models/common_meal_model.dart';
import '../../../common/widgets/common_meal_list_cell.dart';
import '../../home_page/models/homo_page_category_model.dart';
import '../../../global/provider/meal_list_provider.dart';


class YSHMealListPage extends StatelessWidget {
  static const String routeName = '/mealListPage';
  const YSHMealListPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final categoryModel = ModalRoute.of(context)?.settings.arguments as YSHHomePageCategoryModel;
    return Scaffold(
      appBar: AppBar(
        title: Text(categoryModel.title ?? ''),
      ),
      body: const YSHMealListPageContent(),
    );
  }
}

class YSHMealListPageContent extends StatelessWidget {
  const YSHMealListPageContent({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final categoryModel =
    ModalRoute.of(context)?.settings.arguments as YSHHomePageCategoryModel;
    return Selector<YSHMealListProvider, List<YSHCommonMealModel>>(
      selector: (_, mealProvider) {
        return mealProvider.getFliteredMealList().where((element) {
          return element.categories!.contains(categoryModel.id);
        }).toList();
      },
      builder: (_, mealList, __) {
        return ListView.builder(
            itemCount: mealList.length,
            itemBuilder: (_, index) {
              return YSHMealListCell(mealList[index]);
            });
      },
      shouldRebuild: (perv, next) => !listEquals(perv, next),
    );
  }
}

/**
 * SmartRefresher(
    enablePullDown: true,
    enablePullUp: true,
    header: const ClassicHeader(),
    footer: const ClassicFooter(),
    controller: _refreshController,
    onRefresh: _onRefresh,
    onLoading: _onLoading,
    child: ListView.builder(
    itemBuilder: (_, index) => Card(child: Center(child: Text(items[index]))),
    itemExtent: 100.0,
    itemCount: items.length,
    ),
    );
 */